<template>
  <div class="link flex">
    <table border="1" class="tabledata">
      <tr>
        <td colspan="18" class="bg" style="font-size: 16px; font-weight: bold">
          配煤指标及焦炭质量情况
        </td>
      </tr>
      <tr>
        <td rowspan="24"><div style="width: 40px;">配煤管理</div></td>
        <td><div style="width: 40px;">序号</div></td>
        <td>煤种名称</td>
        <td>1#煤塔配比原配比</td>
        <td>2#煤塔配比原配比</td>
        <td>1#煤塔配比变更后</td>
        <td>2#煤塔配变更后</td>
        <td>日耗量</td>
        <td>水分</td>
        <td></td>
        <td><div style="width: 40px;"></div></td>
        <td>存量</td>
        <td rowspan="17" style="width: 40px;"><div style="width: 40px;">焦炭质量</div></td>
        <td rowspan="2">指标</td>
        <td colspan="2">干熄</td>
        <td></td>
        <td></td>
      </tr>
      <tr v-for="item in 19">
        <td>{{item}}</td>
        <td><input type="text" class="dinput" v-model="inputs[item-1]['mzmc_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['mzmc_' + item]}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['onemtpb_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['onemtpb_' + item]}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['twomtpb_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['twomtpb_' + item]}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['onemtpbu_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['onemtpbu_' + item]}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['twomtpbu_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['twomtpbu_' + item]}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['rhl_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['rhl_' + item]}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['sf_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['sf_' + item]}}</span></td>
        <td></td>
        <td></td>
        <td><input type="number" class="dinput" v-model="inputs[item-1]['cl_'+item]" v-if="!date.isup && isbmfc"/><span v-else>{{inputs[item - 1]['cl_' + item]}}</span></td>
        <!-- 第一行 -->
        <td v-if="item==1">白班</td>
        <td v-if="item==1">夜班</td>
        <!-- 第二行 -->
        <td v-if="item==2">水分</td>
        <td v-if="item==2"><input type="number" class="dinput" v-model="inputs[item-1]['baishui']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baishui']}}</span></td>
        <td v-if="item==2"><input type="number" class="dinput" v-model="inputs[item-1]['yeshui']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yeshui']}}</span></td>
        <!-- 第三行 -->
        <td v-if="item==3">灰分</td>
        <td v-if="item==3"><input type="number" class="dinput" v-model="inputs[item-1]['baihui']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baihui']}}</span></td>
        <td v-if="item==3"><input type="number" class="dinput" v-model="inputs[item-1]['yehui']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yehui']}}</span></td>
        <!-- 第四行 -->
        <td v-if="item==4">挥发分</td>
        <td v-if="item==4"><input type="number" class="dinput" v-model="inputs[item-1]['baihuifa']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baihuifa']}}</span></td>
        <td v-if="item==4"><input type="number" class="dinput" v-model="inputs[item-1]['yehuifa']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yehuifa']}}</span></td>
        <!-- 第五行 -->
        <td v-if="item==5">硫分</td>
        <td v-if="item==5"><input type="number" class="dinput" v-model="inputs[item-1]['bailiu']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['bailiu']}}</span></td>
        <td v-if="item==5"><input type="number" class="dinput" v-model="inputs[item-1]['yeliu']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yeliu']}}</span></td>
        <!-- 第六行 -->
        <td v-if="item==6">M40</td>
        <td v-if="item==6"><input type="number" class="dinput" v-model="inputs[item-1]['baim40']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baim40']}}</span></td>
        <td v-if="item==6"><input type="number" class="dinput" v-model="inputs[item-1]['yem40']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yem40']}}</span></td>
        <!-- 第7行 -->
        <td v-if="item==7">M10</td>
        <td v-if="item==7"><input type="number" class="dinput" v-model="inputs[item-1]['baim10']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baim10']}}</span></td>
        <td v-if="item==7"><input type="number" class="dinput" v-model="inputs[item-1]['yem10']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yem10']}}</span></td>
        <!-- 第8行 -->
        <td v-if="item==8">反应性</td>
        <td v-if="item==8"><input type="number" class="dinput" v-model="inputs[item-1]['baifyx']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baifyx']}}</span></td>
        <td v-if="item==8"><input type="number" class="dinput" v-model="inputs[item-1]['yefyx']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yefyx']}}</span></td>
        <!-- 第9行 -->
        <td v-if="item==9">反应后强度</td>
        <td v-if="item==9"><input type="number" class="dinput" v-model="inputs[item-1]['baifyqd']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['baifyqd']}}</span></td>
        <td v-if="item==9"><input type="number" class="dinput" v-model="inputs[item-1]['yefyqd']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['yefyqd']}}</span></td>
        <!-- 第10行 -->
        <td v-if="item==10">粒度</td>
        <td v-if="item==10">白班（干）</td>
        <td v-if="item==10">夜班（干）</td>
        <td v-if="item==10" colspan="2">平均粒度</td>
        <!-- 第11行 -->
        <td v-if="item==11">＞80</td>
        <td v-if="item==11"><input type="number" class="dinput" v-model="inputs[item-1]['bg80']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['bg80']}}</span></td>
        <td v-if="item==11"><input type="number" class="dinput" v-model="inputs[item-1]['ye80']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['ye80']}}</span></td>
        <td v-if="item==11" colspan="2"><span>{{ld80avg}}</span></td>
        <!-- 第12行 -->
        <td v-if="item==12">80-60</td>
        <td v-if="item==12"><input type="number" class="dinput" v-model="inputs[item-1]['bg60']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['bg60']}}</span></td>
        <td v-if="item==12"><input type="number" class="dinput" v-model="inputs[item-1]['ye60']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['ye60']}}</span></td>
        <td v-if="item==12" colspan="2"><span>{{ld60avg}}</span></td>
        <!-- 第13行 -->
        <td v-if="item==13">60-40</td>
        <td v-if="item==13"><input type="number" class="dinput" v-model="inputs[item-1]['bg40']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['bg40']}}</span></td>
        <td v-if="item==13"><input type="number" class="dinput" v-model="inputs[item-1]['ye40']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['ye40']}}</span></td>
        <td v-if="item==13" colspan="2"><span>{{ld40avg}}</span></td>
        <!-- 第14行 -->
        <td v-if="item==14">40-25</td>
        <td v-if="item==14"><input type="number" class="dinput" v-model="inputs[item-1]['bg25']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['bg25']}}</span></td>
        <td v-if="item==14"><input type="number" class="dinput" v-model="inputs[item-1]['ye25']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['ye25']}}</span></td>
        <td v-if="item==14" colspan="2"><span>{{ld25avg}}</span></td>
        <!-- 第15行 -->
        <td v-if="item==15">＜25</td>
        <td v-if="item==15"><input type="number" class="dinput" v-model="inputs[item-1]['bg0']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['bg0']}}</span></td>
        <td v-if="item==15"><input type="number" class="dinput" v-model="inputs[item-1]['ye0']" v-if="!date.isup && iszjzx"/><span v-else>{{inputs[item - 1]['ye0']}}</span></td>
        <td v-if="item==15" colspan="2"><span>{{ld0avg}}</span></td>
        <!-- 第16行 -->
        <td v-if="item==16"></td>
        <td v-if="item==16"></td>
        <td v-if="item==16"></td>
        <td v-if="item==16" colspan="2"><span>{{ldavgsum}}</span></td>
        <!-- 第17行 -->
        <td v-if="item==17" colspan="6" rowspan="11">
          <textarea cols="60" rows="15" v-model="content" v-if="!date.isup && isbmfc"></textarea>
          <div v-else style="white-space: pre-line;text-align: left;">{{content}}</div>
        </td>
        
        <td v-if="item>=1 && item<=9"></td>
        <td v-if="item>=1 && item<=9"></td>
      </tr>
      <tr>
        <td>20</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td colspan="2">解冻库耗煤气(万m³)</td>
        <td>槽煤存量</td>
        <td>{{cltotal}}</td>
      </tr>
      <tr>
        <td>21</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td colspan="2"><input type="number" class="dinput" v-model="jdkhmq" v-if="!date.isup && isbmfc"/><span v-else>{{jdkhmq}}</span></td>
        <td colspan="2">净化甲醇废液（m³）</td>
      </tr>
      <tr>
        <td>22</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td colspan="2">煤塔存量（t）</td>
        <td>甲醇</td>
        <td><input type="number" class="dinput" v-model="jiachun" v-if="!date.isup && isbmfc"/><span v-else>{{jiachun}}</span></td>
      </tr>
      <tr>
        <td>23</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td><input type="number" class="dinput" v-model="mtcl1" v-if="!date.isup && isbmfc"/><span v-else>{{mtcl1}}</span></td>
        <td><input type="number" class="dinput" v-model="mtcl2" v-if="!date.isup && isbmfc"/><span v-else>{{mtcl2}}</span></td>
        <td>净化</td>
        <td><input type="number" class="dinput" v-model="jinghua" v-if="!date.isup && isbmfc"/><span v-else>{{jinghua}}</span></td>
      </tr>
      <tr>
        <td colspan="2">合计</td>
        <td></td>
        <td>{{onemtpbtotal}}</td>
        <td>{{twomtpbtotal}}</td>
        <td>{{onemtpbutotal}}</td>
        <td>{{twomtpbutotal}}</td>
        <td>{{rhltotal}}</td>
        <td colspan="2">{{ Number(mtcl1)+Number(mtcl2) }}</td>
        <td>取煤</td>
        <td><input type="number" class="dinput" v-model="qumei" v-if="!date.isup && isbmfc"/><span v-else>{{qumei}}</span></td>
      </tr>
      <tr>
        <td colspan="2" rowspan="3">入炉煤指标</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>水分</td>
        <td>灰分</td>
        <td>挥发分</td>
        <td>硫分</td>
        <td>G</td>
        <td>细度</td>
      </tr>
      <tr>
        <td>白班</td>
        <td></td>
        <td></td>
        <td></td>
        <td><input type="number" class="dinput" v-model="rlmzb.bshuifen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.bshuifen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.bhuifen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.bhuifen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.bhuifafen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.bhuifafen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.bliufen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.bliufen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.bg" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.bg}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.bxidu" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.bxidu}}</span></td>
      </tr>
      <tr>
        <td>夜班</td>
        <td></td>
        <td></td>
        <td></td>
        <td><input type="number" class="dinput" v-model="rlmzb.yshuifen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.yshuifen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.yhuifen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.yhuifen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.yhuifafen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.yhuifafen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.yliufen" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.yliufen}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.yg" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.yg}}</span></td>
        <td><input type="number" class="dinput" v-model="rlmzb.yxidu" v-if="!date.isup && iszjzx"/><span v-else>{{rlmzb.yxidu}}</span></td>
      </tr>
    </table>
  </div>
</template>

<script lang="ts" setup name="pmzbjjtzlqk">
import cache from '@/utils/cache'
import { getPmzbjjtzlqk, pmzbjjtzlqkSave, pmzbjjtzlqkSubmit } from '@/api/report'

const uu = ref(cache.get('userInfo'))
const iszjzx = ref(false)
if(uu.value.id==1||uu.value.role_id.includes(3)||uu.value.role_id.includes(4)||uu.value.role_id.includes(12)){
  iszjzx.value = true
}

const isbmfc = ref(false)
if(uu.value.id==1||uu.value.role_id.includes(3)||uu.value.role_id.includes(4)||uu.value.role_id.includes(5)){
  isbmfc.value = true
}
// 循环生成绑定数据  一共19行
const arr = []  
for(let i=1;i<=19;i++){
  arr.push({
    ['mzmc_'+i]:'',
    ['onemtpb_'+i]:'',
    ['twomtpb_'+i]:'',
    ['onemtpbu_'+i]:'',
    ['twomtpbu_'+i]:'',
    ['rhl_'+i]:'',
    ['sf_'+i]:'',
    ['cl_'+i]:'',
    ['baishui']:'',
    ['yeshui']:'',
    ['baihui']:'',
    ['yehui']:'',
    ['baihuifa']:'',
    ['yehuifa']:'',
    ['bailiu']:'',
    ['yeliu']:'',
    ['baim40']:'',
    ['yem40']:'',
    ['baim10']:'',
    ['yem10']:'',
    ['baifyx']:'',
    ['yefyx']:'',
    ['baifyqd']:'',
    ['yefyqd']:'',
    ['bg80']:'',
    ['bs80']:'',
    ['ye80']:'',
    ['bg60']:'',
    ['bs60']:'',
    ['ye60']:'',
    ['bg40']:'',
    ['bs40']:'',
    ['ye40']:'',
    ['bg25']:'',
    ['bs25']:'',
    ['ye25']:'',
    ['bg0']:'',
    ['bs0']:'',
    ['ye0']:'',
  })
}
// 整表 数据绑定
const inputs = ref(arr)
// 右下角说明文字
const content = ref('记事：')
// 解冻库秏煤气(万m³)	
const jdkhmq = ref(0)
// 煤塔存量（t）	1 - 2 
const mtcl1 = ref(0)
const mtcl2 = ref(0)
// 甲醇，净化，取煤
const jiachun = ref(0)
const jinghua = ref(0)
const qumei = ref(0)
// 入炉煤指标   白班和夜班
const rlmzb = ref({
  b1shuifen:0,
  y1shuifen:0,
  bshuifen:0,
  yshuifen:0,
  bhuifen:0,
  yhuifen:0,
  bhuifafen:0,
  yhuifafen:0,
  bliufen:0,
  yliufen:0,
  bg:0,
  yg:0,
  bxidu:0,
  yxidu:0
})

// 前6个合计
const onemtpbtotal = ref(0)
const twomtpbtotal = ref(0)
const onemtpbutotal = ref(0)
const twomtpbutotal = ref(0)
const rhltotal = ref(0)
const cltotal = ref(0)

const ld80avg = ref(0)
const ld60avg = ref(0)
const ld40avg = ref(0)
const ld25avg = ref(0)
const ld0avg = ref(0)

const ldavgsum = ref(0)

// 深层监听数据修改  根据数据变化 从新计算合计
watch(inputs, async (n) => {
  let i = 1;
  let a = 0, b = 0,c = 0,d = 0,e = 0,f = 0;
  let ld80avg1 = 0,ld60avg1 = 0,ld40avg1 = 0,ld25avg1 = 0,ld0avg1 = 0;
  n.forEach((item)=>{
    a += Number(item['onemtpb_'+i])
    b += Number(item['twomtpb_'+i])
    c += Number(item['onemtpbu_'+i])
    d += Number(item['twomtpbu_'+i])
    e += Number(item['rhl_'+i])
    f += Number(item['cl_'+i])
    if(i==11){
      ld80avg1 = (Number(item['bg80'])+Number(item['ye80']))/2*0.9
    }
    if(i==12){
      ld60avg1 = (Number(item['bg60'])+Number(item['ye60']))/2*0.7
    }
    if(i==13){
      ld40avg1 = (Number(item['bg40'])+Number(item['ye40']))/2*0.5
    }
    if(i==14){
      ld25avg1 = (Number(item['bg25'])+Number(item['ye25']))/2*0.325
    }
    if(i==15){
      ld0avg1 = (Number(item['bg0'])+Number(item['ye0']))/2*0.125
    }
    i++
  });
  onemtpbtotal.value = a.toFixed(2);
  twomtpbtotal.value = b.toFixed(2);
  onemtpbutotal.value = c.toFixed(2);
  twomtpbutotal.value = d.toFixed(2);
  rhltotal.value = e.toFixed(2);
  cltotal.value = f.toFixed(2);

  ld80avg.value = ld80avg1.toFixed(2)
  ld60avg.value = ld60avg1.toFixed(2)
  ld40avg.value = ld40avg1.toFixed(2)
  ld25avg.value = ld25avg1.toFixed(2)
  ld0avg.value = ld0avg1.toFixed(2)

  ldavgsum.value = (ld80avg1+ld60avg1+ld40avg1+ld25avg1+ld0avg1).toFixed(2)
},{ deep: true })

const save = async () => {
  let userInfo = cache.get('userInfo')
  let res = await pmzbjjtzlqkSave({
    inputs:inputs.value,
    content:content.value,
    jdkhmq:jdkhmq.value,
    mtcl1:mtcl1.value,
    mtcl2:mtcl2.value,
    jiachun:jiachun.value,
    jinghua:jinghua.value,
    qumei:qumei.value,
    rlmzb:rlmzb.value,
    aid: userInfo.id,
    aname: userInfo.name,
    date:date.date,
  })
}

const uuuu = ref(cache.get('role_name'))
// 上报方法，调用接口
const submit = async () => {
  await pmzbjjtzlqkSubmit({
    label:uuuu.value,
    date:date.date,
  })
}

onMounted(() => {
  getData()
})

const getData = async () => {
  getPmzbjjtzlqk(date).then((res)=>{
    if(res.length>0){
      let newarr = []
      res.forEach((item,i)=>{
        let obj = {
          ['mzmc_'+(i+1)]:item.mzmc,
          ['onemtpb_'+(i+1)]:item.onemtpb,
          ['twomtpb_'+(i+1)]:item.twomtpb,
          ['onemtpbu_'+(i+1)]:item.onemtpbu,
          ['twomtpbu_'+(i+1)]:item.twomtpbu,
          ['rhl_'+(i+1)]:item.rhl,
          ['sf_'+(i+1)]:item.sf,
          ['cl_'+(i+1)]:item.cl,
          ['baishui']:item.baishui,
          ['yeshui']:item.yeshui,
          ['baihui']:item.baihui,
          ['yehui']:item.yehui,
          ['baihuifa']:item.baihuifa,
          ['yehuifa']:item.yehuifa,
          ['bailiu']:item.bailiu,
          ['yeliu']:item.yeliu,
          ['baim40']:item.baim40,
          ['yem40']:item.yem40,
          ['baim10']:item.baim10,
          ['yem10']:item.yem10,
          ['baifyx']:item.baifyx,
          ['yefyx']:item.yefyx,
          ['baifyqd']:item.baifyqd,
          ['yefyqd']:item.yefyqd,
          ['bg80']:item.bg80,
          ['bs80']:item.bs80,
          ['ye80']:item.ye80,
          ['bg60']:item.bg60,
          ['bs60']:item.bs60,
          ['ye60']:item.ye60,
          ['bg40']:item.bg40,
          ['bs40']:item.bs40,
          ['ye40']:item.ye40,
          ['bg25']:item.bg25,
          ['bs25']:item.bs25,
          ['ye25']:item.ye25,
          ['bg0']:item.bg0,
          ['bs0']:item.bs0,
          ['ye0']:item.ye0,
        }
        newarr.push(obj)
      })
      inputs.value = newarr
      console.log('=====',inputs.value)
      
      content.value = res[0].content
      jdkhmq.value = res[0].jdkhmq
      mtcl1.value = res[0].mtcl1
      mtcl2.value = res[0].mtcl2
      jiachun.value = res[0].jiachun
      jinghua.value = res[0].jinghua
      qumei.value = res[0].qumei
      rlmzb.value = JSON.parse(res[0].rlmzb)
    }else{
      inputs.value = arr
    }
  })
}

const date = defineProps(['date','isup'])
watch(date, async (n) => {
  getData()
})

defineExpose({
  save,
  submit
})
</script>

<style lang="scss" scoped>
.tabledata {
  width: 100%;
  border: 1px solid #aaa;
  td {
    text-align: center;
    border: 1px solid #aaa;
    padding: 3px;
  }
  .bg{
    background: #ccc;
  }
  .dinput{
    text-align: center;
    border-radius: 5px;
    width: 80px;
    border: 1px solid #ccc;
  }
}
</style>
